﻿@{
    ViewBag.Title = "转库存";
    var invUser = ViewBag.InventoryUser as CubicFWNet.Data.ViewModal.InventoryUserView;
    var orderList = ViewBag.OrderList as List<CubicFWNet.Data.ViewModal.OrderInfo>;
    var noOrder = ViewBag.NoOrder as CubicFWNet.Data.ViewModal.OrderRelationView;
}

<section class="content-header">
    <h1>
        转库存
    </h1>
    <ol class="breadcrumb">
        <li><a href="javascript:void(0);"><i class="fa fa-dashboard"></i>@Resources.Global.PageTitle</a></li>
        <li><a href="@Url.Action("Index","Home")">首页</a></li>
        <li class="active">转库存</li>
    </ol>
</section>

<section class="content">
    <form class="form-horizontal" method="post" id="formMain">
        <div class="form-horizontal">
            <div class="box box-solid">
                <div class="box-nav clearfix">
                </div>
                <div class="box-body">
                    <div class="row">
                        <input type="hidden" id="InventoryUser" name="InventoryUser" value="@invUser.Id" />

                        <div class="form-group col-md-6 col-sm-12">
                            <label class="col-sm-3 control-label">产品名称</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" value="@invUser.ProductName" readonly />
                            </div>
                        </div>

                        <div class="form-group col-md-6 col-sm-12">
                            <label class="col-sm-3 control-label">订单编号</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" value="@invUser.Number" readonly />
                            </div>
                        </div>

                        @if (invUser.OrderID == new Guid())
                        {
                            <div class="form-group col-md-6 col-sm-12">
                                <label class="col-sm-3 control-label">所属销售员</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" value="@noOrder.UserName" readonly />
                                </div>
                            </div>
                        }
                        else
                        {
                        <div class="form-group col-md-6 col-sm-12">
                            <label class="col-sm-3 control-label">所属销售员</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" value="@invUser.UserName" readonly />
                            </div>
                        </div>
                        }

                        <div class="form-group col-md-6 col-sm-12">
                            <label class="col-sm-3 control-label">库存数量</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" value="@invUser.Amount" readonly />
                            </div>
                        </div>

                        <div class="form-group col-md-6">
                            <label class="col-sm-3 control-label">转出到</label>
                            <div class="col-sm-9">
                                <input type="hidden" name="Order" id="Order" />
                                <span class="btn btn-primary" onclick="ShowOrderList()"> 选 择 订 单 </span>&nbsp;&nbsp;&nbsp;&nbsp;
                                <span id="OrderName"></span>
                            </div>
                        </div>

                        <div class="form-group col-md-6 col-sm-12">
                            <label class="col-sm-3 control-label">转出数量</label>
                            <div class="col-sm-9">
                                <input type="number" id="Amount" name="Amount" class="form-control" value="@invUser.Amount" />
                            </div>
                        </div>

                    </div>

                    <div class="row">
                        <div class="form-group col-md-6 col-sm-12">
                            <label for="Memo" class="col-sm-3 control-label">备注</label>
                            <div class="col-sm-9">
                                <textarea rows="3" class="form-control" id="Memo" name="Memo" maxlength="500"></textarea>
                            </div>
                        </div>
                    </div>

                    <div class="row">
                        <div class="form-group col-md-6 col-sm-12">
                            <label for="Creator" class="col-sm-3 control-label">创建人</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="Creator" name="Tolerance" value="@ViewBag.RealName" readonly="readonly" />
                            </div>
                        </div>
                        <div class="form-group col-md-6 col-sm-12">
                            <label for="CreateTime" class="col-sm-3 control-label">创建时间</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="CreateTime" value="@DateTime.Now.ToString("yyyy-MM-dd HH:mm")" readonly="readonly" />
                            </div>
                        </div>
                    </div>

                </div>

                <div class="box-footer">
                    <div class="box-footer">
                        <span class="btn btn-primary " onclick="FormSub()">确 定</span>&nbsp;&nbsp;&nbsp;&nbsp;
                        <label class="danger">@ViewBag.Info</label>
                    </div>
                </div>
            </div>
        </div>
    </form>
</section>

<!--选择订单-->
<div class="modal" id="orderList" style="display: none">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">选择订单</h4>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="form-group col-sm-8">
                        <label for="GetCus" class="col-sm-3 ">搜索</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="GetOrder" name="GetOrder" placeholder="请输入订单号或销售员..." onkeyup="GetOrder()" />
                        </div>
                    </div>
                </div>
                <div id="OrderList">
                    @foreach (var item in orderList)
                    {
                            <div class="btn btn-default orderItem col-xs-12" data-orderID="@item.Id" data-orderName="@item.SalerName &nbsp; @item.Number" data-sel="0" style="margin:8px" data-dismiss="modal">@item.SalerName -- @item.Number </div>
                    }
                </div>
            </div>
            <div class="modal-footer">
                <a role="button" class="btn btn-default pull-left" data-dismiss="modal">关闭</a>
                <a role="button" class="btn btn-primary" data-dismiss="modal">确定</a>
            </div>
        </div>
    </div>
</div>

@section Scripts {
    <script>
        $(document).ready(function () {
            $('#footable').footable();
        });

        //提交表单
        function FormSub() {
            var amount = $("#Amount").val();
            var max = @invUser.Amount;

            if (amount=="" || amount>max || amount<0) {
                $.modalAlert("请输入正确的数量！", "warning");
                return false;
            }

            $("#formMain").submit();
        }


        //弹窗显示订单列表
        function ShowOrderList() {
            $("#orderList").modal();
        }

        //点击选择订单
        $(".orderItem").click(function () {
            var id = $(this).attr("data-orderID");
            var name = $(this).attr("data-orderName");
            $("#OrderName").html(name);
            $("#Order").val(id);
            
            $(".orderItem").addClass("btn-default");
            $(".orderItem").removeClass("btn-primary");
            $(this).addClass("btn-primary");
            $(this).removeClass("btn-default");
        });

        //搜索订单
        function GetOrder() {
            var name = $("#GetOrder").val().trim();

            var list = $("#OrderList .orderItem");
            var num = list.size();

            for (var i = 0; i < num; i++) {
                var cusName = $("#OrderList .orderItem").eq(i).attr("data-orderName");
                if (cusName.indexOf(name) >= 0) {
                    $("#OrderList .orderItem").eq(i).show();
                }
                else {
                    $("#OrderList .orderItem").eq(i).hide();
                }
            }
        }
    </script>
}